﻿using AutoMapper;
using MediatR;
using Traceability.APP.Application.Command.Breeds;
using Traceability.APP.Application.Command.Traceablitys;
using Traceability.Damoin;
using Traceability.ErrorCode;
using Traceability.Infaseture;

namespace Traceability.APP.Application.CommandHadnLer.Breeds
{
    public class UpdateImmunityCommandHandLer : IRequestHandler<UpdateImmunityCommand, APIResult<int>>
    {

        private readonly IBaseRepostiy<Immunity> _immunity;
        private readonly IMapper mapper;
        public UpdateImmunityCommandHandLer(IBaseRepostiy<Immunity> immunity, IMapper mapper)
        {
            _immunity = immunity;
            this.mapper = mapper;
        }
        public async Task<APIResult<int>> Handle(UpdateImmunityCommand request, CancellationToken cancellationToken)
        {

            APIResult<int> result = new APIResult<int>();
            var list = mapper.Map<Immunity>(request);
            list.UpdateUserTime = DateTime.Now;
            var res = await _immunity.Update(list);
           
            result.Code = ResultCode.Ok;
            result.Message = "免疫信息修改成功";
            result.Data = res;
            return await Task.FromResult(result);
        }
    }
}
